package com.hycat.mail.member.controller;

import java.util.Arrays;
import java.util.Map;
import com.hycat.mail.member.entity.MemberEntity;
import com.hycat.mail.member.vo.LoginParam;
import com.hycat.mail.member.vo.RegisterParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hycat.mail.member.service.MemberService;
import com.hycat.mail.common.utils.PageUtil;
import com.hycat.mail.common.utils.R;


/**
 * 会员
 *
 * @author lzhycat
 * @email 2680628835@qq.com
 * @date 2022-07-16 20:27:41
 */
@RestController
@RequestMapping("/member/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    @PostMapping("/register")
    public R register(@RequestBody RegisterParam registerParam){
       memberService.register(registerParam);
       return R.ok("注册成功");
    }

    @PostMapping("/login")
    public R register(@RequestBody LoginParam loginParam){
         String token = memberService.login(loginParam);
         return R.ok("登录成功").put("token", token);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("member:member:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtil page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     * @return
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("member:member:info")
    public MemberEntity info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);
		return member;
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("member:member:update")
    public R update(@RequestBody com.hycat.mail.member.entity.MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("member:member:delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
}
